# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libplacebo
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.3.0
pkgrel=1
pkgdesc="Reusable library for GPU-accelerated video/image rendering primitives (mingw-w64)"
arch=('any')
url="https://github.com/haasn/libplacebo/"
depends=("${MINGW_PACKAGE_PREFIX}-vulkan")
makedepends=("${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
license=('LGPLv2.1')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/haasn/libplacebo/archive/v${pkgver}.tar.gz"
        libplacebo.pc
        0004-avoid-ffsll.patch)
sha256sums=('009e6d06699dcbde63b29667af2ca754c3ba935eb2e855087c03edbaaf43e983'
            'd7520d2ca9038ebef528c924a6216d69859282ea96b87f4ecdc6e6d7a01d5eb2'
            '77e25e046e6cacb946d685bc6be2ad566a36586546fa4e56889f47c4ff9515da')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0004-avoid-ffsll.patch
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  ${MINGW_PREFIX}/bin/meson \
    --buildtype plain \
    ../${_realname}-${pkgver}

  ninja
}

package() {
  cd "${srcdir}"/build-${CARCH}
  DESTDIR=${pkgdir}${MINGW_PREFIX} ninja install
  
  mkdir -p ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig
  cp ${srcdir}/libplacebo.pc ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/
  sed -e "s|@PLACEBO_VERSION@|${pkgver}|g" \
    -i ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/libplacebo.pc
}
